package gnippets.domain

/*
 * Copyright 2008 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 *  <p>The user class represents a single signed up user of the application</p>
 *
 *  @author <a href='mailto:kouphax@gmail.com'>James Hughes</a>
 *  @author <a href='mailto:dmitriy.kopylenko@gmail.com'>Dmitriy Kopylenko</a>
 */
class GnippetsUser {

    static hasMany = [
    
        /**
         *  list of gnippets posted by the user
         */        
        postedGnippets:Gnippet,
        
        /**
         *  list of comments made by the user
         */
        comments:Comment,
        
        /**
         *  list of user's favorite gnippets
         */        
        favoriteGnippets:FavoriteGnippet,
        
        /**
         *  list of gnippets which the user has already rated
         */
        ratedGnippets:GnippetRating
    ]
    
    /**
     *  Username of the user
     */
    String username
    
    /**
     *  Password for the user
     */
    String password
    
    /**
     *  Users real name
     */
    String realName
    
    /**
     *  Users email address
     */
    String email
        
    /**
     *  Users website
     */
    URL url
    
    static constraints = {    
        username(unique:true, nullable:false, blank:false)        
        password(minSize:5)
        realName(nullable:true, blank:true)
        email(nullable:false, email:true, blank:false, unique:true)
        url(nullable:true)
    }

    //TODO add business methods, etc. (in fact, encapsulate as much business logic as possible in all the relevant domain classes)
}
